import { defineStore } from "pinia";

export const userInfoStore = defineStore('user', {
    state: () => ({
        uid: '',
        username: '',
        phoneNumber: '',
        headPortraitUrl: ''
    }),
    getters: {

    },
    actions: {
        update(uid?: string, username?: string, phoneNumber?: string, headPortraitUrl?: string) {
            this.headPortraitUrl = headPortraitUrl ? headPortraitUrl : this.headPortraitUrl;
            this.uid = uid ? uid : this.uid;
            this.username = username ? username : this.username;
            this.phoneNumber = phoneNumber ? phoneNumber : this.phoneNumber;
        },
        reset() {
            this.headPortraitUrl = '';
            this.uid = '';
            this.username = '';
            this.phoneNumber = '';
        },
        setUrl(headPortraitUrl?: string) {
            this.headPortraitUrl = headPortraitUrl ? headPortraitUrl : this.headPortraitUrl;
        }
    },
    persist: {
        enabled: true,
        strategies: [
            {
                key: 'user',
                storage: localStorage,
                paths: ['uid', 'username', 'headPortraitUrl', 'phoneNumber']
            }
        ]
    }
});
